<template>
	<view class="my-page">
		<u-navbar leftIconColor="#ffffff" :autoBack="true" :placeholder="true" bgColor="rgba(255,255,255,0.0)">
			<view slot="center" class="nav-title">
				订单详情
			</view>
		</u-navbar>
		<view class="head" v-if="info.purchase">
			<view class="head-left" v-if="info.purchase.status == 1">
				<view class="head-title">
					等待对方支付
				</view>
				<view class="head-time">
					<view>剩余时间</view>
					<view class="count" v-if="info.userInfo">
						<u-count-down :time="info.userInfo.deal_time * 1000" @change="onChange" format="HH:mm:ss"
							autoStart millisecond>
							<view class="time">
								<view class="time__custom">
									<text
										class="time__custom__item">{{ timeData.hours>10?timeData.hours:timeData.hours}}</text>
								</view>
								<text class="time__doc">:</text>
								<view class="time__custom">
									<text class="time__custom__item">{{ timeData.minutes }}</text>
								</view>
								<text class="time__doc">:</text>
								<view class="time__custom">
									<text class="time__custom__item">{{ timeData.seconds }}</text>
								</view>
							</view>
						</u-count-down>
					</view>
					<!-- <view>内付款</view> -->
				</view>
			</view>
			<view class="head-left" v-if="info.purchase.status == 2">
				<view class="head-title">
					查看支付凭证
				</view>
				<view class="head-time">
					<view>请在</view>
					<view class="count" v-if="info.userInfo">
						<u-count-down :time="info.userInfo.deal_time * 1000" @change="onChange" format="HH:mm:ss"
							autoStart millisecond>
							<view class="time">
								<view class="time__custom">
									<text
										class="time__custom__item">{{ timeData.hours>10?timeData.hours:timeData.hours}}</text>
								</view>
								<text class="time__doc">:</text>
								<view class="time__custom">
									<text class="time__custom__item">{{ timeData.minutes }}</text>
								</view>
								<text class="time__doc">:</text>
								<view class="time__custom">
									<text class="time__custom__item">{{ timeData.seconds }}</text>
								</view>
							</view>
						</u-count-down>
					</view>
					<view>内确定</view>
				</view>
			</view>
			<view class="head-left" v-if="info.purchase.status == 3">
				<view class="head-title">
					已完成
				</view>
			</view>
		</view>
		<view class="item" v-if="info.purchase">
			<view class="item-top">
				<image class="logo" :src="info.purchase.logo" mode=""></image>
				<view class="item-right">
					<view class="item-title">
						{{info.purchase.name}}
					</view>
					<view class="item-cont">
						<view class="info-item">
							<view class="info-num">
								{{info.purchase.reward}}
							</view>
							<view class="info-text">
								利润(CNY)
							</view>
						</view>
						<view class="info-item">
							<view class="info-num">
								{{info.purchase.rate}}
							</view>
							<view class="info-text">
								收益率/日
							</view>
						</view>
						<view class="info-item">
							<view class="info-num info-title">
								{{info.purchase.price}}
							</view>
							<view class="info-text">
								价值
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="content" v-if="info.voucher">
			<view class="code" @click="goeveopen(info.voucher)">
				<image :src="info.voucher" mode="widthFix"></image>
			</view>
			<view class="btn" v-if="info.purchase.status == 2">
				<u-button color="#090B08" shape="circle" type="primary" text="确认支付凭证" @click="goquer"></u-button>
			</view>
		</view>
		<view class="content" v-if="info.userInfo">
			<view class="tell-item">
				<view>买方</view>
				<view class="tell-right" @click="gotell(info.userInfo.tel)">
					<view>{{info.userInfo.tel||'无'}}</view>
					<image src="../../../static/home/tell.png" mode="heightFix"></image>
				</view>
			</view>
			<view class="tell-item none-item">
				<view>紧急联系人</view>
				<view class="tell-right" @click="gotell(info.userInfo.urgent_tel)">
					<view>{{info.userInfo.urgent_tel||'无' }}</view>
					<image src="../../../static/home/tell.png" mode="heightFix"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				info: {},
				timeData: {},
			}
		},
		onLoad(e) {
			this.id = e.id
			this.uploadVoucherIndex()
		},
		methods: {
			goeveopen(e) {
				let arr = []
				arr.push(e)
				uni.previewImage({
					urls: arr // 需要预览的图片http链接列表
				});
			},
			goquer() {
				let app = this
				uni.showModal({
					title: '提示',
					content: '是否确定收款',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							let params = {
								id: app.id
							}
							app.$Request({
								method: 'POST',
								url: '/api/trade/confirmOrder',
								data: params,
								ismsg: true,
							}).then(res => {
								if (res.code == 1) {
									app.uploadVoucherIndex()
								}
							})

						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			gotell(tell) {
				if (!tell) {
					uni.showToast({
						title: '手机号为空！',
						icon: 'none'
					})
					return
				}
				uni.makePhoneCall({
					phoneNumber: tell
				})
			},
			onChange(e) {
				this.timeData = e
			},
			uploadVoucherIndex() {
				let params = {
					id: this.id
				}
				this.$Request({
					method: 'POST',
					url: '/api/trade/confirmOrderIndex',
					data: params,
					ismsg: false,
				}).then(res => {
					if (res.code == 1) {
						this.info = res.data
					}
				})

			},
		}
	}
</script>
<style>
	page {
		background: #000000;
	}
</style>
<style lang="scss" scoped>
	.my-page {
		min-height: 100vh;
		position: relative;
		background-image: url('../../../static/login/login-bg.png');
		background-repeat: no-repeat;
		background-size: 100% 593px;
		padding: 30rpx;

		.nav-title {
			color: #ffffff;
		}

		.head {
			padding: 0 30rpx;
			margin-top: 30rpx;

			.head-left {
				color: #666;

				.head-title {
					color: #ffffff;
					font-size: 42rpx;
					font-weight: 900;
					text-align: center;
				}

				.head-time {
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 26rpx;
					margin-top: 20rpx;

					.count {
						padding: 0 5rpx;

						.time {
							@include flex;
							align-items: center;

							&__custom {
								width: 22px;
								height: 22px;
								border-radius: 4px;
								/* #ifndef APP-NVUE */
								display: flex;
								/* #endif */
								justify-content: center;
								align-items: center;

								&__item {
									color: #52ECFA;
									font-size: 14px;
									text-align: center;
								}
							}

							&__doc {
								color: #52ECFA;
							}

							&__item {
								color: #52ECFA;
								font-size: 16px;
								margin-right: 4px;
							}
						}
					}
				}
			}
		}

		.item {
			margin-top: 30rpx;
			padding: 30rpx;
			border-radius: 30rpx;
			background: #1A1A1B;
			position: relative;
		
			.item-top {
				display: flex;
				align-items: center;
				justify-content: space-between;
		
				.logo {
					width: 130rpx;
					height: 130rpx;
					border-radius: 10rpx;
				}
		
				.item-right {
					width: 75%;
		
					.item-title {
						font-size: 32rpx;
						color: #ffffff;
					}
		
					.item-cont {
						display: flex;
						justify-content: space-between;
						text-align: center;
						margin-top: 10rpx;
		
						.info-item {
							font-size: 28rpx;
		
							.info-num {
								color: #ffffff;
								font-size: 32rpx;
								font-weight: bold;
								margin-top: 5rpx;
							}
		
							.info-text {
								color: #999;
								font-size: 24rpx;
								margin-top: 5rpx;
							}
		
							.info-title {
								color: #52ECFA;
								font-size: 32rpx;
							}
						}
					}
				}
			}
		
		}

		.content {
			padding: 30rpx;
			margin-top: 30rpx;
		
			.info-item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				font-size: 26rpx;
				color: #666;
				margin-bottom: 20rpx;
		
				.item-right {
					display: flex;
					align-items: center;
					color: #ffffff;
				}
		
				image {
					width: 24px;
					height: 12px;
					margin-left: 10rpx;
				}
			}
		
			.code {
				text-align: center;
				padding: 20rpx 0;
				margin-top: 60rpx;
		
				image {
					width: 300rpx;
					height: 300rpx;
				}
			}
		
			.tips {
				font-size: 24rpx;
				color: #FFD7A2;
				padding-top: 20rpx;
			}
		
			.btn {
				margin-top: 40rpx;
			}
		
			.tell-item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding-bottom: 20rpx;
				margin-bottom: 20rpx;
				font-size: 26rpx;
				color: #666;
		
				.tell-right {
					display: flex;
					align-items: center;
					color: #ffffff;
		
					image {
						width: 32rpx;
						height: 32rpx;
						margin-left: 20rpx;
					}
				}
			}
		
			.none-item {
				padding: 0;
				border: none;
				margin: 0;
			}
		}
	}
</style>